<template>
  <div>
    <!-- 信息修改 -->
    <el-dialog
      v-model="infoEditVisible"
      title="信息修改"
      width="800px"
    >
      <el-form
        ref="infoEditFormRef"
        :model="infoEditForm"
        :rules="rules"
        label-width="auto"
      >
      <el-row :gutter="20">

        <el-col :span="24">
          <el-form-item
            label="手机号"
            prop="phone"
            required
            :rules="[
                { required: true, pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的手机号', trigger: 'blur' }
            ]"
          >
            <el-input
              v-model="infoEditForm.phone"
              placeholder="请输入手机号"
              clearable
            />
          </el-form-item>
        </el-col>

        <template v-if="checkRole(7)">

        <el-col :span="12">
          <el-form-item
            label="姓名："
            prop="name"
            required
          >
            <el-input
              v-model="infoEditForm.name"
              placeholder="请输入姓名"
              clearable
              style="width: 100%;"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="身份证号："
            prop="cardIdNoHide"
            required
          >
            <el-input
              v-model="infoEditForm.cardIdNoHide"
              placeholder="请输入身份证号"
              :disabled="true"
              style="width: 100%;"
            />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item
            label="身份证正面："
            prop="cardPositive"
          >
            <imageUpload
              v-model="infoEditForm.cardPositive"
              modelKey="url"
              :limit="1"
              :isShowTip="false"
            />
          </el-form-item>
        </el-col>

         <el-col :span="12">
           <el-form-item
             label="身份证反面："
             prop="cardBack"
           >
             <imageUpload
               v-model="infoEditForm.cardBack"
               modelKey="url"
               :limit="1"
               :isShowTip="false"
             />
           </el-form-item>
         </el-col>

        <el-col :span="12">
          <el-form-item
            label="人脸照片："
            prop="facePic"
          >
            <imageUpload
              v-model="infoEditForm.photoPath"
              modelKey="url"
              :limit="1"
              :isShowTip="false"
            />
          </el-form-item>
        </el-col>
</template>
      </el-row>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="infoEditVisible = false">关 闭</el-button>
          <el-button
            type="primary"
            :loading="subLoading"
            @click="infoEditSubmit"
          >确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="infoEdit" lang="ts">
import api from '@/api/workMag/contractInquiry';
import { ContractInquiryVO, InfoEditVo } from '@/api/workMag/contractInquiry/types';
import { checkRole } from '@/utils/permission'; // 权限判断函数

const emit = defineEmits(['getList'])
// 信息修改
const infoEditFormRef = ref<ElFormInstance>();
const infoEditVisible = ref(false);
const subLoading = ref(false);
const infoEditForm = ref<InfoEditVo>({
  name: '',
  id: '',
  cardPositive: '',
  cardBack: '',
  workId: '',
  merId: '',
  cardIdNoHide: '',
  photoPath: '',
  phone: '',
  phoneNoHide: ''
});


const rules = ref({
  name: [{ required: true, message: '请输入姓名', trigger: 'change' }]
});




const infoDialogShowFun = async (row: ContractInquiryVO) => {
  infoEditVisible.value = true;
  const res = await api.selUpUwInfo(row.id);
  infoEditForm.value = res.data;
  infoEditForm.value.phone = res.data.phoneNoHide;
  infoEditForm.value.cardId = '';
  infoEditForm.value.id = res.data.workId;
};
const infoEditSubmit = async () => {
  infoEditFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      subLoading.value = true;
      let params = infoEditForm.value;
      delete params.createTime;
      delete params.cardId;
      const res = await api.selUpUwInfoEditSubmit(params);
      infoEditVisible.value = false;
      ElMessage.success('修改成功！');
      subLoading.value = false;
      emit('getList',{});
    }
  });
};

defineExpose({
  infoDialogShowFun
});
</script>

<style lang="scss" scoped>
</style>
